home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Misc Servers / Zope.exe / OBJECTREF.PY < prev    next >
Encoding:
Python Source  |  1999-04-13  |  7.6 KB  |  216 lines

  1. ##############################################################################
  2. # Zope Public License (ZPL) Version 1.0
  3. # -------------------------------------
  4. # Copyright (c) Digital Creations.  All rights reserved.
  5. # This license has been certified as Open Source(tm).
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are
  8. # met:
  9. # 1. Redistributions in source code must retain the above copyright
  10. #    notice, this list of conditions, and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. #    notice, this list of conditions, and the following disclaimer in
  13. #    the documentation and/or other materials provided with the
  14. #    distribution.
  15. # 3. Digital Creations requests that attribution be given to Zope
  16. #    in any manner possible. Zope includes a "Powered by Zope"
  17. #    button that is installed by default. While it is not a license
  18. #    violation to remove this button, it is requested that the
  19. #    attribution remain. A significant investment has been put
  20. #    into Zope, and this effort will continue if the Zope community
  21. #    continues to grow. This is one way to assure that growth.
  22. # 4. All advertising materials and documentation mentioning
  23. #    features derived from or use of this software must display
  24. #    the following acknowledgement:
  25. #      "This product includes software developed by Digital Creations
  26. #      for use in the Z Object Publishing Environment
  27. #      (http://www.zope.org/)."
  28. #    In the event that the product being advertised includes an
  29. #    intact Zope distribution (with copyright and license included)
  30. #    then this clause is waived.
  31. # 5. Names associated with Zope or Digital Creations must not be used to
  32. #    endorse or promote products derived from this software without
  33. #    prior written permission from Digital Creations.
  34. # 6. Modified redistributions of any form whatsoever must retain
  35. #    the following acknowledgment:
  36. #      "This product includes software developed by Digital Creations
  37. #      for use in the Z Object Publishing Environment
  38. #      (http://www.zope.org/)."
  39. #    Intact (re-)distributions of any official Zope release do not
  40. #    require an external acknowledgement.
  41. # 7. Modifications are encouraged but must be packaged separately as
  42. #    patches to official Zope releases.  Distributions that do not
  43. #    clearly separate the patches from the original work must be clearly
  44. #    labeled as unofficial distributions.  Modifications which do not
  45. #    carry the name Zope may be packaged in any form, as long as they
  46. #    conform to all of the clauses above.
  47. # Disclaimer
  48. #   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
  49. #   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50. #   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  51. #   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
  52. #   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  53. #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  54. #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  55. #   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  56. #   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  57. #   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  58. #   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  59. #   SUCH DAMAGE.
  60. # This software consists of contributions made by Digital Creations and
  61. # many individuals on behalf of Digital Creations.  Specific
  62. # attributions are listed in the accompanying credits file.
  63. ##############################################################################
  64. """Object Reference implementation"""
  65.  
  66. __version__='$Revision: 1.5 $'[11:-2]
  67.  
  68.  
  69. import sys, os, string, Globals, Acquisition
  70. from HelpUtil import HelpBase, classobject
  71. from HelpUtil import is_class, is_module
  72. from Globals import HTMLFile
  73. from urllib import quote
  74.  
  75.  
  76.  
  77.  
  78. class ObjectItem(HelpBase, classobject):
  79.     """ """
  80.     __roles__=None
  81.  
  82.     hs_main=HTMLFile('objectitem', globals())
  83.  
  84.     hs_cicon='HelpSys/hs_dnode'
  85.     hs_eicon='HelpSys/hs_dnode'
  86.  
  87.     def hs_id(self):
  88.         return self._obj_.meta_type
  89.  
  90.     def hs_url(self):
  91.         return quote(self._obj_.meta_type)
  92.     
  93.     hs_title=hs_id
  94.  
  95.     def __getattr__(self, name):
  96.         if name in ('isDocTemp', '__call__'):
  97.             raise AttributeError, name
  98.         return getattr(self.__dict__['_obj_'], name)
  99.  
  100.     def get_method_list(self):
  101.         rdict=classobject.get_method_dict(self)
  102.         perms=self.__ac_permissions__
  103.         mdict={}
  104.         mlist=[]
  105.         for p in self.__ac_permissions__:
  106.             pname=p[0]
  107.             fnames=p[1]
  108.             for fname in fnames:
  109.                 if rdict.has_key(fname):
  110.                     fn=rdict[fname]
  111.                     fn.permission=pname
  112.                     mdict[fname]=fn                    
  113.         keys=mdict.keys()
  114.         keys.sort()
  115.         for key in keys:
  116.             fn=mdict[key]
  117.             if not hasattr(fn._obj_, '__doc__'):
  118.                 continue
  119.             doc=fn._obj_.__doc__
  120.             if hasattr(fn._obj_, '__class__') and \
  121.                fn._obj_.__class__.__doc__ is doc:
  122.                 continue
  123.             
  124.             mlist.append(mdict[key])
  125.         del rdict
  126.         del mdict
  127.         return mlist
  128.  
  129.     hs_objectvalues__roles__=None
  130.     def hs_objectvalues(self):
  131.         return []
  132.  
  133.     
  134.  
  135. class ObjectRef(HelpBase):
  136.     """ """
  137.     __names__=None
  138.     __roles__=None
  139.  
  140.     hs_main=HTMLFile('objectref', globals())
  141.  
  142.     hs_cicon='HelpSys/hs_cbook'
  143.     hs_eicon='HelpSys/hs_obook'
  144.  
  145.     hs_id   ='ObjectRef'
  146.     hs_title='Object Reference'
  147.     hs_url  =hs_id
  148.     
  149.     def hs_deferred__init__(self):
  150.         # This is necessary because we want to wait until all
  151.         # products have been installed (imported).
  152.         dict={}
  153.         for k, v in sys.modules.items():
  154.             if v is not None and k != '__builtins__':
  155.                 dict=self.hs_search_mod(v, dict)
  156.         keys=dict.keys()
  157.         keys.sort()
  158.         __traceback_info__=(`dict`,)
  159.         for key in keys:
  160.             setattr(self, key, dict[key])
  161.         self.__names__=keys
  162.  
  163.     def hs_search_mod(self, mod, dict):
  164.         # Root through a module for things that look like
  165.         # createable object classes.
  166.         hidden=('Control Panel', 'Principia Draft', 'simple item',
  167.                 'Broken Because Product is Gone')
  168.         for k, v in mod.__dict__.items():
  169.             if is_class(v) and hasattr(v, 'meta_type') and \
  170.                hasattr(v, '__ac_permissions__'):
  171.                 if callable(v.meta_type):
  172.                     try: meta_type=v.meta_type()
  173.                     except:
  174.                         # Ack. probably a ZClass :(
  175.                         meta_type=None
  176.                 else: meta_type=v.meta_type
  177.                 if (meta_type is not None) and (meta_type not in hidden):
  178.                     dict[meta_type]=ObjectItem(k, v)
  179.             if is_module(v) and hasattr(v, '__path__'):
  180.                 dict=self.hs_search_mod(v, dict)
  181.         return dict
  182.  
  183.     hs_objectvalues__roles__=None
  184.     def hs_objectvalues(self):
  185.         if self.__names__ is None:
  186.             self.hs_deferred__init__()
  187.         items=[]
  188.         for id in self.__names__:
  189.             items.append(getattr(self, id))
  190.         return items
  191.  
  192.     def __getitem__(self, key):
  193.         return self.__dict__[key].__of__(self)
  194.  
  195.